package com.alipay.demo.trade.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class GoodDateUtil {
	
	 /* 
     * 获取时间
     */  
	  public static Long getTime() {
		  return Instant.now().toEpochMilli()/1000;
	  }
	
	 /* 
     * 将时间转换为时间戳
     */    
    public static long dateToStamp(String s) throws ParseException{
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        return ts;
    }

    /*
     * 将时间转换为时间戳
     */
    public static long dateToStamp1(String s) throws ParseException{
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        return ts;
    }
    /* 
     * 将时间戳转换为时间
     */
    public static String stampToDate(String s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long(s);
        Date date = new Date(lt);
        res = simpleDateFormat.format(date);
        return res;
    }
    
    /* 
     * 将Date时间 转成  String时间
     */
    public static String DateToString(Date date){
    	 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	 return sdf.format(date);
    }
    
    /* 
     * 将String时间 转成  Date时间
     */
    public static Date DateStringToDate(String date) throws ParseException{
    	 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   	 
   	    return sdf.parse(date);
   }
    
    /* 
     * 将long时间 转成  Date时间
     */
    public static String longToDate(long lo){    

    	Date date = new Date(lo);   

    	SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    

    	return sd.format(date);  

    	}
    
    
    public static void main(String[] args) throws ParseException {
//    	System.out.println("当前时间："+DateToString(new Date()));
//    	String dateString= GoodDateUtil.DateToString(new Date());
//		//String sjc= GoodDateUtil.dateToStamp(dateString);
//		System.out.println("当前时间 时间戳："+sjc);
//		String sjc2= GoodDateUtil.stampToDate("1289427561");
//		System.out.println("当前时间："+sjc2);
//
//		DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault());
//		Long i=Instant.now().toEpochMilli()/1000;
//		Long i1=(long) (1543195704*1000);
//         System.out.println("longToDate="+longToDate(i1));
		
		
	}
    
  
   
}
